package com.hongshan.wallet.core.wallet

import android.app.Application
import android.databinding.ObservableField
import com.hongshan.wallet.base.MyViewModel
import com.hongshan.wallet.bean.BindInfoBean
import com.hongshan.wallet.http.HttpClient
import com.hongshan.wallet.tryRun
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch

/**
 * Copyright Zhangxx.
 * Copyright (c) 2019
 * All rights reserved
 *
 * @project  : Wallet
 * @package  : com.example.wallet.core.wallet
 * @author   : zhangxx
 * @date     : 2019/3/26
 * @email    : qq957413212@hotmail.com
 * @desc     : //TUDO
 */
class AccountManageViewModel(application: Application) : MyViewModel(application) {

    val alipayStatus = ObservableField("未设置")

    val wechatStatus = ObservableField("未设置")

    var alipay: BindInfoBean? = null
    var wechat: BindInfoBean? = null

    val adapter = AccountTypeRecycleAdapter()

    fun getBankCardList() {
        GlobalScope.launch(Dispatchers.Main) {
            val bindResult = GlobalScope.async(Dispatchers.IO) {
                tryRun { HttpClient.httpApi.getBindInfo().execute() }
            }
            val bindBody = bindResult.await()?.body()
            if (bindBody?.code == 0) {
                adapter.list = bindBody.data.list as MutableList<BindInfoBean>
                adapter.notifyDataSetChanged()
            }
        }
    }

}